from django.db import models
from rest_framework.serializers import ModelSerializer

# Create your models here.


class Carousel(models.Model):
    lbt = models.CharField(max_length=200, verbose_name='轮播图')

    class Meta:
        db_table = 'carousel'

    def __str__(self):
        return self.lbt


class Category(models.Model):
    name = models.CharField(max_length=10, verbose_name='商品种类')

    class Meta:
        db_table = 'category'

    def __str__(self):
        return self.name


class Goods(models.Model):
    sku_name = models.CharField(max_length=300, verbose_name='商品名')
    title = models.CharField(max_length=300, verbose_name='描述')
    instruction = models.CharField(max_length=300, verbose_name='特点')
    img = models.CharField(max_length=300, verbose_name='商品图片')
    price = models.IntegerField(verbose_name='原价')
    selling_price = models.IntegerField(verbose_name='折后价')
    count = models.IntegerField(verbose_name="数量", default=0)
    stock = models.IntegerField(verbose_name="库存", default=0)
    cate = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name="商品类别")

    class Meta:
        db_table = 'goods'

    def __str__(self):
        return self.sku_name


class GoodImg(models.Model):
    goods_id = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品')
    img = models.CharField(max_length=200, verbose_name='图片')
    title = models.CharField(max_length=200, verbose_name='图片的描述')

    class Meta:
        db_table = 'goodimg'

    def __str__(self):
        return self.goods_id


class CarouselSER(ModelSerializer):
    class Meta:
        model = Carousel
        fields = '__all__'


class CategorySER(ModelSerializer):
    class Meta:
        model = Category
        fields = '__all__'


class GoodsSER(ModelSerializer):
    class Meta:
        model = Goods
        fields = '__all__'


class GoodImgSER(ModelSerializer):
    class Meta:
        model = GoodImg
        fields = '__all__'
